<?php

// $Id: milestone.inc 24 2010-11-11 07:33:55Z mjohnson60@gmail.com $
//
// $Author: mjohnson60@gmail.com $
// $Date: 2010-10-29 07:27:52 -0400 (Fri, 29 Oct 2010) $
//
// $Rev: 16 $
//


class Milestone extends DBObject
{
	var $mid = 0;
	
	var $name = 'Please enter a name.';
	var $date = 0;

	/**
	 * Milestone::Milestone()
	 * 
	 * @return
	 */
	public function Milestone($data = NULL)
	{
		$this->table = 'milestone';
		
		$this->id_name = 'mid';
		
		$this->fields = array(
			'name' => "'%s'", 'date' => '%d'
		);
		
		parent::DBObject($data);
	}

	public static function formatted_date($date)
	{
		return date('M j, Y g:ia', $date);
	}

	/**
	 * Milestone::schema()
	 * 
	 * @return
	 */
	public static function schema()
	{
		return 'CREATE TABLE IF NOT EXISTS `milestone` (
    			  `mid` int(10) unsigned NOT NULL AUTO_INCREMENT,
    			  `name` varchar(75) NOT NULL,
    			  `date` int(10) unsigned NOT NULL,
    			  PRIMARY KEY (`mid`),
    			  UNIQUE KEY `mid_UNIQUE` (`mid`)
    			) ENGINE=InnoDB DEFAULT CHARSET=utf8';
	}

	/**
	 * Milestone::install()
	 * 
	 * @return
	 */
	public static function install()
	{
		db_query('DROP TABLE IF EXISTS milestone');
		$result = db_query(Milestone::schema());
		
		if ($result !== FALSE)
		{
			db_query("INSERT INTO milestone (name, date) VALUES ('Please enter a name.', 0)");
			db_query("UPDATE milestone SET mid=0 WHERE name='Please enter a name.'");
			db_query('ALTER TABLE milestone AUTO_INCREMENT=1');
			
			system_set_message('The <code>milestone</code> table was successfully created.');
			
			return TRUE;
		}
		else
		{
			system_set_message('The <code>milestone</code> table was not created.');
			
			return FALSE;
		}
	}

	/**
	 * Milestone::uninstall()
	 * 
	 * @return
	 */
	public static function uninstall()
	{
		$result = db_query('DROP TABLE IF EXISTS milestone');
		if ($result !== FALSE)
		{
			system_set_message('The <code>milestone</code> table was successfully removed.');
			
			return TRUE;
		}
		else
		{
			system_set_message('The <code>milestone</code> table was not removed.');
			
			return FALSE;
		}
	}
}
